home *** CD-ROM | disk | FTP | other *** search
- /*** ***/
- /*** a test program for changing the fonts ***/
- /*** ***/
- /*** This will display the fonts that can be used ***/
- /*** in dvtools programs. It will show the ***/
- /*** information needed for the DV.INI file ***/
- /*** ***/
-
- #include <windows.h>
- #include "std.h"
- #include "dvtools.h"
- #include "dvstd.h"
- #include "Tfundecl.h"
- #include "GRfundecl.h"
- #include "dvGR.h"
-
- int CALLBACK getnumfaces();
- int CALLBACK getfacenames();
- int CALLBACK draw_it();
- void show_fonts();
-
- struct face_struct
- {
- int num_faces; /* total num of faces on system */
- int face_to_fill; /* index int face_names array */
- char **face_names;
- int width;
- } ;
-
- HDC bigboy;
-
- int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- OBJECT screen;
- VIEW view;
- DRAWPORT drawport;
- long window_height;
- long window_width;
-
- int argc; /* number of args */
- char **argv; /* command line args- unix style */
-
- /* this call makes the unix style argv */
- /* it's just here for demo only */
- make_argv(&argc,&argv,GetCommandLine());
-
- window_height = 480;
- window_width = 640;
-
- /* you always have to do this to use our stuff */
- TInit(NULL,NULL);
-
- screen = TscOpenSet("W", NULL, V_WINDOW_X, 0,
- V_WINDOW_Y, 0, V_WINDOW_WIDTH, window_width,
- V_WINDOW_HEIGHT, window_height, V_END_OF_LIST);
-
- if ( screen == (OBJECT) NULL )
- {
- /* could not open a window, die die die */
- exit( -1 );
- }
-
- view = TviCreate();
-
- drawport = TdpCreateStretch( screen, view, NULL, NULL );
-
-
- show_fonts();
-
- /* Sleep will not work very well on win32s */
- Sleep(2000);
-
- TdpDestroy(drawport);
- TviDestroy(view);
- TscCloseCurrentScreen();
- TTerminate();
- return(1);
-
- }
-
-
-
-
-
- /*** ***/
- /*** This file shows how to change fonts in a DataViews ***/
- /*** program running on Windows NT. This done by using ***/
- /*** GRget and GRset. GRget is used to get the window ***/
- /*** handle for the current device. That handle is then ***/
- /*** used to find what fonts are available. The current ***/
- /*** font used by DataViews is then changed using GRset.***/
-
- void show_fonts()
- {
- struct face_struct faces;
- int x;
- HDC hdc;
- HWND win_handle;
-
-
- /* This call will get the window handle used by the */
- /* DataViews driver for the current device */
- GRget(V_WIN32_WINDOW_HANDLE,&win_handle,V_END_OF_LIST);
-
- /* This win32 call will get the handle to the display */
- /* context for the window handle*/
- hdc = GetDC(win_handle);
- bigboy = hdc;
- faces.num_faces = 0;
- /* This win32 call will get the number of font faces */
- /* that are available */
- EnumFonts(hdc,NULL,getnumfaces,(LPARAM)&(faces.num_faces));
-
- faces.face_names = ( char **) malloc(
- sizeof(char *) * faces.num_faces);
- faces.face_to_fill = 0;
-
- /* This win32 call will get the names of all the faces */
- EnumFonts(hdc,NULL,getfacenames,(LPARAM)&faces);
-
-
- for( x = 0; x < faces.num_faces ; x++)
- {
- /* for each face, look at all the fonts in that face */
- EnumFonts(hdc,faces.face_names[x],draw_it,(LPARAM)&faces);
-
- }
-
- ReleaseDC(win_handle,hdc);
- }
-
-
- /** this function is used with EnumFonts to find out how many **/
- /** font faces exist on the current device **/
- int CALLBACK getnumfaces(LOGFONT *log_font, TEXTMETRIC *text_metric,
- DWORD font_type,int * param)
- {
-
- (*param)++;
- return(1);
- }
-
- /** this function is used with EnumFonts to get the name of each **/
- /** font face **/
- int CALLBACK getfacenames(LOGFONT *log_font, TEXTMETRIC *text_metric,
- DWORD font_type,struct face_struct *param)
- {
- int len;
-
- len = strlen(log_font->lfFaceName);
- len++;
- param->face_names[param->face_to_fill] = (char *)malloc(len);
- strcpy(param->face_names[param->face_to_fill],log_font->lfFaceName);
- (param->face_to_fill)++;
-
- return(1);
- }
-
-
- int CALLBACK draw_it(LOGFONT *log_font, TEXTMETRIC *text_metric,
- DWORD font_type,struct face_struct *param)
- {
- HFONT this_font = 0;
- DV_POINT p;
- char mess[64];
- int x,y;
- SIZE size;
-
- /* Most DataViews character display routines must have */
- /* fixed width fonts. So show only fixed width fonts. */
- if ( text_metric->tmAveCharWidth == text_metric->tmMaxCharWidth)
- {
- this_font = CreateFontIndirect(log_font);
- if ( this_font != 0 )
- {
-
- GRerase();
-
- /* this call to GRset is the one that changes one of the */
- /* DataViews hardware fonts to your choice of a font. */
- /* the argument "1" is the index of the font you want */
- /* changed. the next argumant, "this_font", is a HFONT */
- /* created by the CreateFontIndirect() win32 API function*/
- GRset(V_WIN32_NEWFONT,1,this_font,V_END_OF_LIST);
-
- /* This call makes the DataViews driver use index 1 as the */
- /* current font */
- GRch_size(1,1);
-
- /* this loop draws a text string to the window using */
- /* the current font */
- p.y = 200;
- {
- int b;
-
- GetTextExtentPoint(bigboy,"M",1,&size);
- sprintf(mess,"name=%s x=%d y=%d ",log_font->lfFaceName,
- size.cx,size.cy);
- for( b = 630; b > 0 ; b--)
- {
- p.x = b;
- GRmove(&p);
- GRtext(mess);
- GRflush();
- }
- }
- Sleep(700);
-
- }
-
- }
- return( TRUE);
- }
-
-
-
-
-